package com.fanghuaman.checkcode.service.impl;

import com.fanghuaman.checkcode.service.CheckCodeService;
import org.springframework.stereotype.Component;

import java.util.Random;

/**
 * @author shiminghui
 * @date 2024/9/9 20:35
 * @description: TODO
 */
@Component("NumberCheckCodeGenerator")
public class NumberCheckCodeGenerator implements CheckCodeService.CheckCodeGenerator {
    @Override
    public String generate(int length) {
        String str = "0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(10);
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }
}
